package com.android.svmc.app.mobile.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.svmc.app.mobile.activity.R;
import com.android.svmc.app.mobile.model.CommentModel;
import com.android.svmc.app.mobile.view.FontTextView;


public class CommentAdapter extends BaseAdapter {
	Context mcontext;
	private LayoutInflater mInflater;
	ArrayList<CommentModel> listComment = new ArrayList<CommentModel>();
	private boolean online;
	
	public CommentAdapter(Context context,
			ArrayList<CommentModel> comments) {
		mcontext = context;
		listComment = comments;
		mInflater = LayoutInflater.from(context);

	}
	public CommentAdapter(Context context,
			ArrayList<CommentModel> comments,boolean online) {
		mcontext = context;
		listComment = comments;
		mInflater = LayoutInflater.from(context);
		this.online = online;

	}
	@Override
	public int getCount() {
		return listComment.size();
	}

	@Override
	public Object getItem(int position) {
		return listComment.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	

	@Override
	public boolean isEmpty() {
		return false;
	}
	@Override
	public View getView(int position, View view, ViewGroup parent) {
		CommentModel commentItem = listComment.get(position);
		CommentHolder holder;
		if(view == null){
			mInflater = (LayoutInflater) mcontext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = mInflater.inflate(R.layout.comment_layout, null);
			holder = new CommentHolder();
			
			holder.thumbnail = (ImageView)view.findViewById(R.id.comment_adapter_img_thumbnail);
			holder.content =(TextView)view.findViewById(R.id.comment_adapter_content);
			holder.date =(TextView)view.findViewById(R.id.comment_adapter_date);
			holder.name =(TextView)view.findViewById(R.id.comment_adapter_name);
			view.setTag(holder);
		}else {
			holder =(CommentHolder)view.getTag();
		}
		holder.name.setText(commentItem.getNameSubmit());
		FontTextView.setfontHelveticaBold(holder.name, mcontext);
		String contentTemp = commentItem.getContentConment();
		int size = contentTemp.length();
		// remove tag <p> and </n> at the firt and the last string comment
		holder.content.setText(Html.fromHtml(contentTemp.substring(3, size-6)));
		//holder.content.setText(commentItem.getContentConment());
		holder.date.setText(commentItem.getDateConment());
		holder.thumbnail.setImageResource(R.drawable.icon_default);
		
		return view;
	}
	static class CommentHolder {
		TextView name;
		TextView content;
		TextView date;
		ImageView thumbnail;
	}

}
